const app = getApp()
var queryUrl = app.globalData.queryUrl;
var QQMapWX = require('../../utils/qqmap-wx-jssdk.min.js');
var qqmapsdk;

Page({
  data: {
    txt: "分类",
    select: false,
    talks: [],
    openId: '',
    id: 0,//第N个视频
    show: false,
    autoplay: true,
    videoContext: null,
    percent: 0,
    isPlay: true,
    fullScreen: false,
    playUrl: [],
    orientation: "vertical",
    objectFit: "contain",
    muted: false,
    backgroundMuted: false,
    debug: false,
    show: [false, false, false, false, false, false],
    vid: 0,
    pagey: '',
    index_num: 1,
    gps: false,
    longitude: '108.953349',//钟楼
    latitude: '34.26591',//钟楼
    city: ''
  },
  // 跳转页面
  imgGo: function () {
    wx.navigateTo({
      url: '../service/head/head',
    })
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
   
  },

  /**
     * 生命周期函数--监听页面初次渲染完成
     */
  onReady: function () {
    // this.videoContext = wx.createVideoContext('myVideo')
  },
  // 分享
  onShareAppMessage: function (res) {
    // console.log(res);
    if (res.from === "shares") { }
    return {
      title: "哈哈",
      desc: "我是中国人",
      path: "pages/resume/click/purchase",
      imageUrl: "../../../images/gift6.png",
      success: function (res) {
        console.log("成功", res);

      }
    }
  },


  onScrollLoad: function () {

  },
  //点击我显示底部弹出框
  clickme: function () {
    this.showModal();
  },

  //显示对话框
  showModal: function () {
    // 显示遮罩层
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation
    animation.translateY(300).step()
    this.setData({
      animationData: animation.export(),
      showModalStatus: true
    })
    setTimeout(function () {
      animation.translateY(0).step()
      this.setData({
        animationData: animation.export()
      })
    }.bind(this), 0)
  },
  //隐藏对话框
  hideModal: function () {
    // 隐藏遮罩层
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation
    animation.translateY(300).step()
    this.setData({
      animationData: animation.export(),
    })
    setTimeout(function () {
      animation.translateY(0).step()
      this.setData({
        animationData: animation.export(),
        showModalStatus: false
      })
    }.bind(this), 200)
  },
  bindShowMsg() {
    this.setData({
      select: !this.data.select,
      color: 'black'
    })
  },
  mySelect(e) {
    var name = e.currentTarget.dataset.name
    this.setData({
      txt: name,
      select: false
    })
  },
  // 跳转个人简历模块
  goResume: function () {
    wx.navigateTo({
      url: '../head/head?currentData=1',
    })
  },
  goSearch: function () {
    wx.navigateTo({
      url: '../../search/search',
    })
  },
  goMap: function () {
    wx.navigateTo({
      url: '../../map/map',
    })
  },
  // 点击播放按钮
  play: function () {
    var that = this;
    console.log(that.data.index_num)
    that.setData({
      index_num: that.data.index_num + 1
    });
    if (that.data.index_num % 2 == 1) {
      console.log('播放')
      //console.log(that.videoContext.onTimeUpdate);
      that.videoContext.play()
      that.setData({ isPlay: true })
      // that.setData({
      //   display_play: 'none'
      // })
    } else {
      console.log('暂停')
      that.videoContext.pause()
      that.setData({ isPlay: false })
    }
  },
  // 开始播放
  bindPlay: function () {
    this.videoContext.play()
  },

  // 暂停播放
  bindPause: function () {
    this.videoContext.pause();
  },

  // 播放完毕
  bindEnded: function () {
    this.bindPlay()
  },
  // 下面主要模仿滑动事件
  touchstart: function (e) {
    console.log(e)
    this.setData({
      pagey: e.changedTouches[0].pageY
    })
    console.log(e.changedTouches[0].pageY)
  },
  touchmove: function (e) {

  },
  touchend: function (e) {
    console.log("--" + e.changedTouches[0].pageY)
    if (e.changedTouches[0].pageY - this.data.pagey > 100) {

      var isZero = this.data.vid == 0
      console.log(isZero);
      var id = this.data.vid == 0 ? 0 : this.data.vid - 1
      if (isZero) {
        wx.showToast({
          title: '已是第一个！',
        })
      } else {
        this.setData({
          vid: id,
          index: 1

        })
        var that = this
        setTimeout(function () {
          that.bindPlay()
        }, 500)
      }
    } else if (this.data.pagey - e.changedTouches[0].pageY > 100) {
      var islast = this.data.vid == this.data.vsrc.length - 1
      var lid = this.data.vid == this.data.vsrc.length - 1 ? this.data.vsrc.length - 1 : this.data.vid + 1
      if (islast) {
        wx.showToast({
          title: '已是最后一个！',
        })
      } else {
        this.setData({
          vid: lid,
          index: 1
        })
      }
      var that = this
      setTimeout(function () {
        that.bindPlay()
      }, 500)
    }
  },
  timeupdate: function (e) {
    var val = e.detail.currentTime;
    var max = e.detail.duration;
    var percent = Math.round(val / max * 10000) / 100;
    this.setData({ percent: percent })
  },
})